#ifndef _MESH
#define _MESH

#include <d3dx9.h>
#include <vector>
#define  RESOURCE_TYPE_MESH 7


struct ObjectVertex
{
	ObjectVertex(){}
	ObjectVertex(D3DXVECTOR3 pos, D3DXVECTOR3 norm, float u, float v)
	{
		_pos = pos;
		_norm = norm;
		_u = u;
		_v = v;
	}
	D3DXVECTOR3 _pos, _norm;
	float _u, _v;
	static const DWORD FVF;
};




class WPENGIN_API CMesh : public CGraphicsFileResource,public IRenderable
{
	friend class OBJECT;
	friend class CMeshInstance;
	friend struct RAY;
public:
	CMesh(const TCHAR * resName,const TCHAR * szFilePath, D3DPOOL pool=D3DPOOL_DEFAULT);	 
	~CMesh();	 
	void Render(bool bMateril=true);
	virtual  void OnD3D9LostDevice();
	virtual HRESULT   OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice);
	HRESULT     SetVertexDecl( LPDIRECT3DDEVICE9 pd3dDevice, const D3DVERTEXELEMENT9* pDecl,
	bool bAutoComputeNormals = true, bool bAutoComputeTangents = true,
	bool bSplitVertexForOptimalTangents = false );

   BoundingSphere * GetBoundingSphere();
	ID3DXMesh * GetMesh(){return m_pMesh;}
	void RenderProgressive();
	void SetLOD(int numFaces);
	virtual void OnD3D9FrameRender( float fElapsedTime );

private:
	ID3DXMesh *m_pMesh;
	ID3DXPMesh *m_pProgressiveMesh;
	std::vector<IDirect3DTexture9*> m_textures;
	std::vector<D3DMATERIAL9> m_materials;
	D3DMATERIAL9 m_white;
};

#endif